package com.google.code.timeeditapplication.view.implementation;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

import com.google.code.timeeditapplication.R;
import com.google.code.timeeditapplication.controller.implementation.ScheduleController;
import com.google.code.timeeditapplication.model.implementation.ScheduleItem;

public class DayViewActivity extends Activity {
	private CustomView cV;

	// Creating a test object for the schedule view.
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dayview);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

		final Date date = ScheduleController.getInstance().getActiveDate();
		final GregorianCalendar cal = new GregorianCalendar();
		cal.set(date.getYear() + 1900, date.getMonth(), date.getDate());

		final Scanner sc = new Scanner(date.toString());

		final TextView weekNumber = (TextView) findViewById(R.id.dayviewweeklabel);
		weekNumber.setText("V." + cal.get(Calendar.WEEK_OF_YEAR));
		final TextView dayLabel = (TextView) findViewById(R.id.dayviewdaylabel);
		dayLabel.setText(sc.next() + "  " + cal.get(Calendar.DATE) + "/"
				+ (cal.get(Calendar.MONTH) + 1));

		this.cV = ((CustomView) findViewById(R.id.dayCustomView));

		this.cV.addScheduleList(ScheduleController.getInstance()
				.getDaySchedule().getItems(), 16);

	}

	@Override
	protected void onResume() {
		super.onResume();
		@SuppressWarnings("unused")
		final ArrayList<ScheduleItem> list = ScheduleController.getInstance()
				.getDaySchedule().getItems();
		this.cV.addScheduleList(ScheduleController.getInstance()
				.getDaySchedule().getItems(), 16);

	}

	/**
	 * Creates the menu in the day view
	 * 
	 * @param: Menu menu
	 */
	@Override
	public boolean onCreateOptionsMenu(final Menu menu) {
		super.onCreateOptionsMenu(menu);

		final MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.day_view_menu, menu);
		return true;

	}

	/**
	 * @param item
	 */
	@Override
	public boolean onOptionsItemSelected(final MenuItem item) {
		switch (item.getItemId()) {
		case R.id.week_dayview:
			final Intent weekIntent = new Intent(this, WeekViewActivity.class);
			startActivity(weekIntent);
			return true;
		case R.id.month_dayview:
			final Intent monthIntent = new Intent(this, MonthViewActivity.class);
			startActivity(monthIntent);
			return true;
		case R.id.save_as_my_schedule_monthview:
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

}
